package com.bxg.listDemo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//collection123
public class Demo1 {
    public static void main(String[] args) {
       //容器
        Collection<String> collection=new ArrayList<>();
        //添加
        collection.add("苹果");
        collection.add("香蕉");
        collection.add("梨");
        //System.out.println(collection);
        //移除
      /*  boolean b = collection.remove("火龙果");
        System.out.println(b);
        System.out.println("移除后"+collection.toString());*/
        //遍历  迭代器遍历
        Iterator<String> iterator = collection.iterator();

        while (iterator.hasNext()){
            String next = iterator.next();
            if(next.equals("苹果")){
                //collection.remove(next);
                iterator.remove();
            }else {
                System.out.println(next);
            }
        }

        /*增强for遍历时不要对集合进行增删操作*/
        for (String s : collection) {
            System.out.println(s);
        }





    }
}
